import './index.scss';
//这里导入的是未执行的方法
import tpl from './index.tpl';

//模块导出 返回一个对象
export default () => {
  return {
    name: 'header',
    showRemove: false,
    tpl(title, isShow) {
      let oHeader = document.createElement('div');
      oHeader.className = 'header';
      oHeader.innerHTML = tpl().replace(/{{(.*?)}}/g, (node, key) => {
        return {
          title,
          is_show: isShow ? 'show' : ''
        } [key];
      });
      return oHeader;
    },
    //标题右上角编辑按钮功能
    onEditBth() {
      this.showRemove = !this.showRemove;
      const oRemoveCell = Array.from(document.getElementsByClassName('remove-cell')),
        oEditBtn = document.getElementsByClassName('J_editItem')[0];

      oRemoveCell.forEach((elem) => {
        if (this.showRemove) {
          oEditBtn.innerHTML = '关闭';
          elem.className += ' show';
        } else {
          oEditBtn.innerHTML = '编辑';
          elem.className = 'cell remove-cell';
        }
      })
    }
  }
}